module AdminHelper

  # Possible parameters:
  #     :required  (boolean)  
  #     :errorText (text)
  #     :label     (text)
  #     :name      (text)
  #     :value     (text)
  #     :hint      (text)
  #     :valClass  (text) 
  def form_text(params= {})
    errorText         = params[:errorText].to_s.size == 0 ? ''             : params[:errorText].to_s    
    error             = errorText.to_s.size == 0          ? false          : true
    errorclass        = error                             ? 'error'        : ''
    required          = params[:required].nil?            ? false          : params[:required]
    requiredIndicator = required                          ? '<em>*</em> '  : ''
    label             = params[:label].to_s.size == 0     ? 'Label'        : params[:label].to_s
    name              = params[:name].to_s.size == 0      ? 'name'         : params[:name].to_s
    value             = params[:value].to_s.size == 0     ? ''             : params[:value].to_s
    hint              = params[:hint].to_s.size == 0      ? ''             : params[:hint].to_s
    hint              = error ? errorText : (required ? 'Required element' : hint)
    valClass          = params[:valClass].to_s.size == 0  ? ''             : params[:valClass].to_s
    valClass += ' required' if required
  
    s = %{
      <div class="ctrlHolder #{errorclass}"> 
        <label for="">#{requiredIndicator}#{label}</label>
        <input name="#{name}" size="35" maxlength="35" type="text" class="textInput #{valClass}" data-default-value="admin" value="#{value}"/> 
        <p class="formHint">#{hint}</p> 
      </div>
    }   

    
    return s.html_safe
  end

end
